<?php

/**
 * Institucion form.
 *
 * @package    BCWeb
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class InstitucionForm extends BaseInstitucionForm{
  
  public function configure(){
       $this->widgetSchema['pais_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model'     => 'Pais',
            'add_empty' => 'Select pais',
            'ajax'      => true,
            'url'          =>  sfContext::getInstance()->getController()->genUrl('home/buscarPais'),
        ));
        //$this->widgetSchema['pais_id']->setDefault ('Argentina');
        // if you want to load without ajax (because few data):
        #$this->widgetSchema['country_id'] = new sfWidgetFormDoctrineChoice(array(
        #    'model'     => 'Country', 
        #    'add_empty' => 'Select country',
        #));                 

        $this->widgetSchema['provincia_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model'        => 'Provincia', 
            'depends'      => 'Pais',
            'add_empty'    => 'Select provincia',
            'ajax'         => true,            
            // took the opportunity to show other options
//            'ref_method'   => 'getCountryId',
            'url'          =>  sfContext::getInstance()->getController()->genUrl('home/buscarRegionesPorPais'),
            #'cache'        => true,
            // the same of sfWidgetForm{Doctrine|Propel}Choice are available
            'order_by'      => array('name', 'asc'),
            #'method'       => '__toString',
            #'key_method'   => 'getId',
            #'table_method' => 'getBigCountries',
        ));

        $this->widgetSchema['partido_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model'     => 'Partido', 
            'depends'   => 'Provincia',
            'add_empty' => 'Select partido',
            'ajax'      => true,
            'url'          =>  sfContext::getInstance()->getController()->genUrl('home/buscarChildrenByRegion'),
            'order_by'  => array('name', 'asc'),
        )); 
//$this->widgetSchema['partido_id']->setOption('is_hidden', 'true');
        $this->widgetSchema['localidad_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model'     => 'Localidad', 
            'depends'   => 'Partido',
            'add_empty' => 'Select localidad',
            'ajax'      => true,
            'order_by'  => array('name', 'asc'),
        )); 
        $this->widgetSchema['barrio_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model'     => 'Barrio', 
            'depends'   => 'Localidad',
            'add_empty' => 'Select barrio',
            'ajax'      => true,
            'order_by'  => array('name', 'asc'),
        )); 
        // always the selects order has to be according to the dependency.
        // ich means: country > state > city
//        $this->widgetSchema->moveField('partido_id', 'after', 'provincia_id');
//        $this->widgetSchema->moveField('localidad_id', 'after', 'partido_id');

        // validators

//        $this->validatorSchema['pais_id'] = new sfValidatorDoctrineChoice(array(
//                    'model' => 'Pais',
//                ));
//
//        $this->validatorSchema['provincia_id'] = new sfValidatorDoctrineChoice(array(
//                    'model' => 'Provincia',
//                ));
//        $this->validatorSchema['partido_id'] = new sfValidatorDoctrineChoice(array(
//                    'model' => 'Partido',
//                ));
  }
}
